home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / PCA Icon Arranger ƒ / MacInit.p < prev    next >
Text File  |  1998-06-20  |  54KB  |  2,457 lines

  1. unit MacInit;
  2.  
  3. { Modification History }
  4. { 06/03/1998 PhC }
  5. { • Correction d'un bug dans l'affichage des valeurs propres }
  6. { • Correction d'un bug dans Dispose (err. -113) }
  7. { 05/25/1998 PhC }
  8. { • Modification pour CodeWarrior }
  9. {   uses StandardFile, etc... }
  10. {   MaxReel et MinReel 10E320->10E300 }
  11. {        Modification TrouveVolume }
  12. {        InitGraf et autres qd }
  13. {   StringToReel etc... ne pas utiliser! }
  14. {        Divers appels -> Universal Interfaces (i.e. GetDItem -> GetDialogItemText }
  15. {            (utilisation de InterfacesUI }
  16. {            TpprPort- > TpprPortRef }
  17. {        round -> system.round }
  18.  
  19. interface
  20.  
  21.     uses
  22. {$ifc undefined THINK_PASCAL}
  23.         StandardFile, TextUtils, fp, Devices, Fonts, Sound, ToolUtils, 
  24. {$elsec}
  25.         InterfacesUI, 
  26. {$endc}
  27.         SANE, Printing;
  28.  
  29.  
  30. { Declarations to make the CW compiler happy. }
  31. { Do not use any of these calls in actual code! }
  32. {$ifc undefined THINK_PASCAL}
  33.     type
  34.         DecStr = Str255;
  35.  
  36.     procedure Num2Str (f: decform;
  37.                                     x: Extended;
  38.                                     var s: DecStr);
  39.  
  40.     function Str2Num (s: DecStr): Extended;
  41.  
  42. {$endc}
  43.  
  44.     const
  45.         MaxReel = 10E300;
  46.         MinReel = -10E300;
  47.         Epsilon = 10E-7;
  48.         MenuHeight = 20;
  49.         FileMenuID = 299;
  50.         AppleID = 300;
  51.         EditID = 301;
  52.         TitreID = 400;
  53.         FichID = 1000;
  54.         ReelID = 2000;
  55.         IntID = 2001;
  56.         CardID = 5000;
  57.         RefID = 5100;
  58.         FabricID = 5200;
  59.         NellyID = 5300;
  60.         ShowfID = 5400;
  61.         MenuID = 6000;
  62.         MenuDessin = 6001;
  63.         MenuFichiers = 6002;
  64.         MenuPr = 6004;
  65.         SortieID = 9000;
  66.         ErrfatID = 300;
  67.         ErrFileID = 301;
  68.         QbinaireID = 500;
  69.         ErrNbID = 700;
  70.         Enteteid = 800;
  71.         NbBits = 32;
  72.         NbBitsl1 = 31;
  73.         IntBytes = 2;
  74.         CarBytes = 2;
  75.         PtrBytes = 4;
  76.         BitsBytes = 4;
  77.         BoolBytes = 1;
  78.         LongBytes = 4;
  79.         ReelBytes = 10;
  80.         TrieBytes = 14;
  81.  
  82.     type
  83.         EventSet = set of 0..inGoAway;
  84.         Alpha = packed array[1..10] of Char;
  85.         PtrFile = ^FileType;
  86.         FileType = record
  87.                 FileNumber, VolNumber: Integer;
  88.                 vName: Boolean;
  89.                 Name: Str255;
  90.             end;
  91.         Ens = set of 0..NbBitsl1;
  92.         Matrice = array[0..4] of Integer;
  93.         Data = record
  94.                 case Integer of
  95.                     1: (
  96.                             Re: Extended
  97.                     );
  98.                     2: (
  99.                             Int: Integer
  100.                     );
  101.                     3: (
  102.                             Car: packed array[1..10] of Char
  103.                     );
  104.             end;
  105.         DataFile = file of Data;
  106.         Trie = record
  107.                 Resultat: Extended;
  108.                 PtrGauche, PtrDroit: Integer;
  109.             end;
  110.         TrieRec = record
  111.                 NoeudTrie: Trie;
  112.             end;
  113.         LongRec = record
  114.                 Long: LongInt;
  115.             end;
  116.         IntRec = record
  117.                 Int: Integer;
  118.             end;
  119.         IntType = ^IntRec;
  120.         ReelRec = record
  121.                 Reel: Extended;
  122.             end;
  123.         ReelType = ^ReelRec;
  124.         LongType = ^LongRec;
  125.         BoolRec = record
  126.                 Bool: Boolean;
  127.             end;
  128.         BoolType = ^BoolRec;
  129.         PtrRec = ^TrieRec;
  130.         CarRec = record
  131.                 Car: Char;
  132.             end;
  133.         CarType = ^CarRec;
  134.         BitsRec = record
  135.                 Bits: Ens;
  136.             end;
  137.         BitsType = ^BitsRec;
  138.         InfoRec = record
  139.                 OffSet1, OffSet2, Rang, NbBytes: Integer;
  140.             end;
  141.         InfoPtr = ^InfoRec;
  142.         idArray = record
  143.                 ID: packed array[1..10] of Char
  144.             end;
  145.         idType = ^idArray;
  146.         PtrType = record
  147.                 case Integer of
  148.                     1: (
  149.                             PtrGen: Ptr
  150.                     );
  151.                     2: (
  152.                             PtrInt: IntType
  153.                     );
  154.                     3: (
  155.                             PtrRee: ReelType
  156.                     );
  157.                     4: (
  158.                             PtrEnt: LongInt
  159.                     );
  160.                     5: (
  161.                             PtrLong: LongType
  162.                     );
  163.                     6: (
  164.                             PtrBool: BoolType
  165.                     );
  166.                     8: (
  167.                             PtrBits: BitsType
  168.                     );
  169.                     9: (
  170.                             PtrTrie: PtrRec
  171.                     );
  172.                     10: (
  173.                             PtrCar: CarType
  174.                     );
  175.                     11: (
  176.                             PtrInfo: InfoPtr
  177.                     );
  178.                     12: (
  179.                             PtrID: idType
  180.                     );
  181.                     13: (
  182.                             PtrStr: StringPtr
  183.                     )
  184.             end;
  185.         FichierType = record
  186.                 Fichier: ^FileType;
  187.                 Delete: Boolean;
  188.             end;
  189.  
  190.     procedure Entredessin (DessinModele: PicHandle;
  191.                                     Ind1, Ind2: Integer);
  192.  
  193.     procedure CloseThings;
  194.  
  195.     procedure DeleteFich (var f: FileType);
  196.  
  197.     function MyFileFilter (ParamBlk: ParmBlkPtr): Boolean;
  198.  
  199.     function StringToReel (var Str: Str255): Extended;
  200.  
  201.     function Reel (i: Integer;
  202.                                     Min, Max: Extended;
  203.                                     StrDefault: StringPtr): Extended;
  204.  
  205.     function FilterForCursor (TheDialog: Dialogptr;
  206.                                     var TheEvent: EventRecord;
  207.                                     var Item: Integer): Boolean;
  208.  
  209.     procedure Dialoginit (Dialogtype: Integer);
  210.  
  211.     procedure Dialogue;
  212.  
  213.     procedure RetourneDialogue;
  214.  
  215.     procedure ErrNombre (i: Integer);
  216.  
  217.     function QuestionBinaire (i: Integer): Boolean;
  218.  
  219.     function StringToInteger (var Str: Str255;
  220.                                     LimInf, LimSup: Integer): Integer;
  221.  
  222.     function Entier (i, LimInf, LimSup: Integer;
  223.                                     St, StrDefault: StringPtr): Integer;
  224.  
  225.     procedure InitThings (AttendCRMouse: Boolean);
  226.  
  227.     function SilentDialog (TheDialog: Dialogptr;
  228.                                     var TheEvent: EventRecord;
  229.                                     var ItemHit: Integer): Boolean;
  230.  
  231.     procedure Erreurs (i, j, k: Integer;
  232.                                     Fatal: Boolean);
  233.  
  234.     procedure StringToFile (var f: FileType;
  235.                                     NoStr, Index, NbLn: Integer);
  236.  
  237.     procedure CreeSortie (var Sortie: FileType;
  238.                                     Ind1, Ind2: Integer);
  239.  
  240.     procedure PrintSetup;
  241.  
  242.     procedure PrIntImage (Dessin: PicHandle;
  243.                                     PrintRect: Rect;
  244.                                     Setup: Boolean);
  245.  
  246.     procedure PrIntFichier (var Fich: FileType);
  247.  
  248.     procedure LisFich (Ind: Integer;
  249.                                     var Entree: FileType;
  250.                                     Stop: Boolean);
  251.  
  252.     procedure LisFichSimil (Ind: Integer;
  253.                                     var Entree: FileType;
  254.                                     Stop: Boolean);
  255.  
  256.     function LireString (i: Integer): Str255;
  257.  
  258.     procedure InitNelly (Notitle, Max: Integer);
  259.  
  260.     procedure MiseaJourd (l: Integer);
  261.  
  262.     procedure MiseaJourg (l: Integer);
  263.  
  264.     procedure NouveauDialogue (ID, j: Integer);
  265.  
  266.     procedure NextEvent (Quoi: EventSet);
  267.  
  268.     procedure ShowFichier (var Fich: FileType;
  269.                                     Index: Integer;
  270.                                     DessinCourant: PicHandle;
  271.                                     R: Rect;
  272.                                     ThereWasAWindow: Boolean);
  273.  
  274.     procedure Interruption;
  275.  
  276.     function LisReel (var t: FileType;
  277.                                     Abort: Boolean): Extended;
  278.  
  279.     function LisEntier (var t: FileType;
  280.                                     Abort: Boolean): LongInt;
  281.  
  282.     function LisID (var t: FileType;
  283.                                     Abort: Boolean): Alpha;
  284.  
  285.     procedure ResetFile (t: FileType);
  286.  
  287.     function EndOfFile (var Fich: FileType): Boolean;
  288.  
  289.     function ReadCar (var Fich: FileType;
  290.                                     Abort: Boolean): Char;
  291.  
  292.     function NextCar (var Fich: FileType;
  293.                                     Abort: Boolean): Char;
  294.  
  295.     procedure Readlnf (var Fich: FileType);
  296.  
  297.     function ReadString (var Fich: FileType;
  298.                                     Abort: Boolean): Str255;
  299.  
  300.     function ReelToString (x: Extended;
  301.                                     Champ, Fraction: Integer): Str255;
  302.  
  303.     procedure WriteString (var Fich: FileType;
  304.                                     Str: Str255);
  305.  
  306.     procedure WriteLnF (var Fich: FileType);
  307.  
  308.     procedure WriteCar (var Fich: FileType;
  309.                                     Car: Char);
  310.  
  311.     procedure WriteSpaces (var Fich: FileType;
  312.                                     NbSpaces: Integer);
  313.  
  314.     procedure WriteInteger (var Fich: FileType;
  315.                                     Nb: LongInt;
  316.                                     Format: Integer);
  317.  
  318.     procedure WriteReal (var Fich: FileType;
  319.                                     Nb: Extended;
  320.                                     Champ, Fraction: Integer);
  321.  
  322.     function GetReal (var t: FileType): Extended;
  323.  
  324.     function GetInteger (var t: FileType): Integer;
  325.  
  326.     function GetTri (var t: FileType): Trie;
  327.  
  328.     function NextTri (var t: FileType): Trie;
  329.  
  330.     procedure GetLn (var t: FileType);
  331.  
  332.     procedure PutReal (var t: FileType;
  333.                                     x: Extended);
  334.  
  335.     procedure PutInteger (var t: FileType;
  336.                                     x: Integer);
  337.  
  338.     procedure PutTri (var t: FileType;
  339.                                     x: Trie);
  340.  
  341.     procedure FileErrHandler (var t: FileType);
  342.  
  343.     procedure TrouveFile (var t: FileType;
  344.                                     Creator, FileType: OSType);
  345.  
  346.     function TrouveVolume: Integer;
  347.  
  348.     function Memoire (Min1, Max1, Min2, Max2, lgBytes: LongInt;
  349.                                     Piege: Boolean): Ptr;
  350.  
  351.     procedure DisposeMemoire (var ThePtr: Ptr);
  352.  
  353.     function AdMat (p: Ptr;
  354.                                     v1, v2: LongInt): PtrType;
  355.  
  356.     function AdVec (p: Ptr;
  357.                                     v: LongInt): PtrType;
  358.  
  359.     function AdLin (p: Ptr;
  360.                                     v1, v2: Integer): PtrType;
  361.  
  362.     function AdBits (mm: Ptr;
  363.                                     i: Integer): PtrType;
  364.  
  365.     procedure Ajoute (Ind: Integer;
  366.                                     mm: Ptr);
  367.  
  368.     function Card (x: Ens): Integer;
  369.  
  370.     function CardVect (m: Ptr): Integer;
  371.  
  372.     procedure Copy (m1, m2: Ptr);
  373.  
  374.     procedure Difference (m1, m2: Ptr);
  375.  
  376.     function Egal (m1, m2: Ptr): Boolean;
  377.  
  378.     procedure Enleve (Ind: Integer;
  379.                                     mm: Ptr);
  380.  
  381.     function InclusEgal (m1, m2: Ptr): Boolean;
  382.  
  383.     procedure Intersection (m0, m1, m2: Ptr);
  384.  
  385.     function Membre (Ind: Integer;
  386.                                     mm: Ptr): Boolean;
  387.  
  388.     procedure NullVec (m: Ptr);
  389.  
  390.     procedure Premier (var i: Integer;
  391.                                     t: Ptr);
  392.  
  393.     procedure Union (m1, m2: Ptr);
  394.  
  395.     function Vide (m: Ptr): Boolean;
  396.  
  397.     var
  398.         LisNombre, ErrNb, vPrinter, FichierSimil, Numeros: Boolean;
  399.         TheDialog, TheCard, TheRef, TheOldDialog: Dialogptr;
  400.         ItemHit, Printertype, MenuNum, MenuItem, NObjSimil, NbDescSimil, NbMots, Hauteur, Largeur, NbFiles, NbOpenFiles: Integer;
  401.         MenuTyp, Ref: LongInt;
  402.         Facteur: Extended;
  403.         Str1, Str2, Str3, Str4, Str5, fTitre, TitreJob, TitreProg, TitreSimil: Str255;
  404.         TextCursor, ClockCursor: CursHandle; {MacIntosh now on}
  405.         Coord: Point;
  406.         Sfr: SfReply;
  407.         Sft: sfTypeList;
  408.         Sortie: FileType;
  409.         Date, Fonction: Alpha;
  410.         AppleMenu, EditMenu, MenuHdl, MenuPrint, MenuFile: MenuHandle;
  411.         ItemHandle1, ItemHandle2, ItemHandle3, ItemHandle4: Handle;
  412.         Box: Rect;
  413.         TheEvent: EventRecord;
  414.         WindowPtr2: WindowPtr;
  415.         AncienPort: GrafPtr;
  416.         MyPrint: TpprPort;
  417.         Finished, PrInter, Opennow, CloseNow: Boolean; { Set to true when were}
  418. {                                                  done }
  419.         ApplRefNum: Integer; { the resource file id of our appl }
  420.         Header: StringHandle; { the text that goes into the Header }
  421.         Footer: StringHandle; { dotto... for the footer }
  422.         PgSetup: ThPrint; { handle to the page setup record }
  423.         DessinCourant: PicHandle;
  424.         MenuDessinHdl, MenuFichHdl: MenuHandle;
  425.         RectAngleCourant: Rect;
  426.         FileErr: OSErr;
  427.         Count, CountByte, CountInteger, CountLongInt, CountReal, CountSimil: LongInt;
  428.         FileArray: array[1..10] of FichierType;
  429.         SilentAlert: ProcPtr;
  430.  
  431. implementation
  432.  
  433.     procedure Entredessin (DessinModele: PicHandle;
  434.                                     Ind1, Ind2: Integer);
  435.  
  436.         var
  437.             Zero: LongInt;
  438.             i, GlobalRef: Integer;
  439.  
  440.     begin
  441.         GetIndString(Str2, FichID, Ind1);
  442.         GetIndString(Str1, FichID, Ind2);
  443.         sfputfile(Coord, Str2, Str1, nil, Sfr);
  444.         if Sfr.Good then begin
  445.             FileErr := Create(Sfr.fName, Sfr.vRefNum, 'RPGR', 'PICT');
  446.             if (FileErr = NoErr) | (FileErr = DupfnErr) then begin
  447.                 FileErr := fsOpen(Sfr.fName, Sfr.vRefNum, GlobalRef);
  448.                 Zero := 0;
  449.                 Count := 4;
  450.                 for i := 1 to 128 do
  451.                     FileErr := fsWrite(GlobalRef, Count, @Zero);
  452.                 FileErr := SetfPos(GlobalRef, fsFromStart, 512); {skip the}
  453. {            MacDraw header}
  454.                 Count := DessinModele^^.PicSize;
  455.                 FileErr := fsWrite(GlobalRef, Count, Ptr(DessinModele^));
  456.                 FileErr := fsClose(GlobalRef);
  457.             end;
  458.         end; {IF reply.good}
  459.     end;
  460.  
  461.     procedure CloseThings;
  462.  
  463.         var
  464.             i: Integer;
  465.             FilePos: LongInt;
  466.  
  467.     begin
  468.         if PrInter then begin
  469.             FileErr := GetfPos(Sortie.FileNumber, FilePos);
  470.             FileErr := SetEOF(Sortie.FileNumber, FilePos);
  471.             PrIntFichier(Sortie);
  472.         end;
  473.         for i := 1 to NbFiles do begin
  474.             with FileArray[i] do
  475.                 if Fichier^.vName then begin
  476.                     if Delete then
  477.                         DeleteFich(Fichier^)
  478.                     else
  479.                         FileErr := fsClose(Fichier^.FileNumber);
  480.                 end;
  481.         end;
  482.         Halt;
  483.     end;
  484.  
  485.     function MyFileFilter (ParamBlk: ParmBlkPtr): Boolean;
  486.  
  487.         var
  488.             Str1, Str2: Str255;
  489.  
  490.     begin
  491.         with ParamBlk^ do begin
  492.             MyFileFilter := IOfRefNum <> 0;
  493.         end;
  494. { Mod. PhC 11/02/98: utiliser ceci pour avoir la liste de tous les fichiers en tout temps }
  495. {$ifc false}
  496.         MyFileFilter := false; { show all files }
  497. {$endc}
  498.     end;
  499.  
  500.     procedure ErrFile (i: Integer;
  501.                                     var t: FileType);
  502.  
  503.     begin
  504.         GetIndString(Str1, ErrFileID, i);
  505.         ParamText(Str1, '', t.Name, '');
  506.         i := StopAlert(ErrFileID, nil);
  507.         CloseThings;
  508.     end; { fin erreur }
  509.  
  510.     procedure FileErrHandler (var t: FileType);
  511.  
  512.         var
  513.             j: Integer;
  514.  
  515.     begin
  516.         if FileErr <> 0 then begin
  517.             FileErr := -FileErr;
  518.             if FileErr >= 50 then begin
  519.                 j := FileErr - 33;
  520.             end
  521.             else begin
  522.                 if FileErr > 43 then begin
  523.                     j := FileErr - 32;
  524.                 end
  525.                 else begin
  526.                     if FileErr = 42 then begin
  527.                         j := 11;
  528.                     end
  529.                     else begin
  530.                         if FileErr >= 33 then begin
  531.                             j := FileErr - 30
  532.                         end
  533.                         else begin
  534.                             j := 28;
  535.                         end;
  536.                     end;
  537.                 end;
  538.             end;
  539.             ErrFile(j, t);
  540.             FileErr := -FileErr;
  541.         end;
  542.     end;
  543.  
  544.     procedure ResetFile (t: FileType);
  545.  
  546.     begin
  547.         FileErr := SetfPos(t.FileNumber, fsFromStart, 0);
  548.         FileErrHandler(t);
  549.     end;
  550.  
  551.     function EndOfFile (var Fich: FileType): Boolean;
  552.  
  553.         var
  554.             FilePos, LogEOF: LongInt;
  555.  
  556.     begin
  557.         with Fich do begin
  558.             FileErr := GetEOF(FileNumber, LogEOF);
  559.             FileErr := GetfPos(FileNumber, FilePos);
  560.         end;
  561.         EndOfFile := LogEOF = FilePos;
  562.     end;
  563.  
  564.     function ReelToString (x: Extended;
  565.                                     Champ, Fraction: Integer): Str255;
  566.  
  567.         var
  568.             f: DecForm;
  569.             s: DecStr;
  570.  
  571.     begin
  572.         f.Style := FixedDecimal;
  573.         f.Digits := Fraction;
  574.         Num2Str(f, x, s);
  575.         if Champ > 0 then begin
  576.             if Length(s) > Champ then begin
  577.                 f.Style := FloatDecimal;
  578.                 Num2Str(f, x, s);
  579.                 if Length(s) > Champ then begin
  580.                     f.Style := FloatDecimal;
  581.                     f.Digits := f.Digits + Champ - Length(s);
  582.                     Num2Str(f, x, s);
  583.                 end;
  584.             end;
  585.         end;
  586.         ReelToString := s;
  587.     end;
  588.  
  589.     function ReadCar (var Fich: FileType;
  590.                                     Abort: Boolean): Char;
  591.  
  592.         var
  593.             CarInt: Integer;
  594.             Count: LongInt;
  595.  
  596.     begin
  597.         if EndOfFile(Fich) then begin
  598.             if (Abort) then
  599.                 ErrFile(1, Fich);
  600.         end
  601.         else begin
  602.             Count := 1;
  603.             FileErr := fsRead(Fich.FileNumber, Count, @CarInt);
  604.             ReadCar := Chr(CarInt div 256);
  605.         end;
  606.     end;
  607.  
  608.     function NextCar (var Fich: FileType;
  609.                                     Abort: Boolean): Char;
  610.  
  611.         var
  612.             CarInt: Integer;
  613.             Count, CurrentPos: LongInt;
  614.  
  615.     begin
  616.         if EndOfFile(Fich) then begin
  617.             if (Abort) then
  618.                 ErrFile(1, Fich);
  619.         end
  620.         else begin
  621.             FileErr := GetfPos(Fich.FileNumber, CurrentPos);
  622.             Count := 1;
  623.             FileErr := fsRead(Fich.FileNumber, Count, @CarInt);
  624.             FileErr := SetfPos(Fich.FileNumber, 1, CurrentPos);
  625.             NextCar := Chr(CarInt div 256);
  626.         end;
  627.     end;
  628.  
  629.     procedure Readlnf (var Fich: FileType);
  630.  
  631.         var
  632.             GenCar: Char;
  633.  
  634.     begin
  635.         if EndOfFile(Fich) then
  636.             GenCar := Chr(13)
  637.         else
  638.             GenCar := ReadCar(Fich, True);
  639.         while (not (EndOfFile(Fich))) and (Ord(GenCar) <> 13) do
  640.             GenCar := ReadCar(Fich, True);
  641.     end;
  642.  
  643.     function ReadString (var Fich: FileType;
  644.                                     Abort: Boolean): Str255;
  645.  
  646.         var
  647.             Count, CurrentPos, LinePos, StrLength: LongInt;
  648.             CarInt: Integer;
  649.             Str: Str255;
  650.  
  651.     begin
  652.         if (EndOfFile(Fich)) and (Abort) then
  653.             ErrFile(1, Fich);
  654.         Str := '';
  655.         StrLength := 0;
  656.         Count := 1;
  657.         FileErr := GetfPos(Fich.FileNumber, CurrentPos);
  658.         repeat
  659.             FileErr := fsRead(Fich.FileNumber, Count, @CarInt);
  660.             StrLength := StrLength + 1;
  661.         until (Count = 0) or (CarInt div 256 = 13);
  662.         FileErr := GetfPos(Fich.FileNumber, LinePos);
  663.         FileErr := SetfPos(Fich.FileNumber, 1, CurrentPos);
  664.         FileErr := fsRead(Fich.FileNumber, StrLength, @Str[1]);
  665.         if Count = 1 then
  666.             StrLength := StrLength - 1; { EOLN }
  667.         Str[0] := Chr(StrLength);
  668.         ReadString := Str;
  669.     end;
  670.  
  671.     procedure WriteString (var Fich: FileType;
  672.                                     Str: Str255);
  673.  
  674.     begin
  675.         Count := Length(Str);
  676.         FileErr := fsWrite(Fich.FileNumber, Count, @Str[1]);
  677.     end;
  678.  
  679.     procedure WriteCar (var Fich: FileType;
  680.                                     Car: Char);
  681.  
  682.         var
  683.             CarInt: Integer;
  684.  
  685.     begin
  686.         Count := 1;
  687.         CarInt := Ord(Car) * 256;
  688.         FileErr := fsWrite(Fich.FileNumber, Count, @CarInt);
  689.     end;
  690.  
  691.     procedure WriteSpaces (var Fich: FileType;
  692.                                     NbSpaces: Integer);
  693.  
  694.         var
  695.             i, SpaceCode: Integer;
  696.  
  697.     begin
  698.         SpaceCode := 8192; { Attention Bug adressage TML: devrait etre 32 au}
  699. {                      lieu de 8192(32x256 }
  700.         Count := 1;
  701.         for i := 1 to NbSpaces do
  702.             FileErr := fsWrite(Fich.FileNumber, Count, @SpaceCode);
  703.     end;
  704.  
  705.     procedure WriteLnF (var Fich: FileType);
  706.  
  707.         var
  708.             crCode: Integer;
  709.  
  710.     begin
  711.         crCode := 3328; { Attention Bug adressage TML: devrait etre 13 au lieu}
  712. {                   de 3328(13x256 }
  713.         Count := 1;
  714.         FileErr := fsWrite(Fich.FileNumber, Count, @crCode);
  715.     end;
  716.  
  717.     procedure WriteInteger (var Fich: FileType;
  718.                                     Nb: LongInt;
  719.                                     Format: Integer);
  720.  
  721.         var
  722.             i: Integer;
  723.  
  724.     begin
  725.         NumToString(Nb, Str1);
  726.         i := Length(Str1);
  727.         WriteSpaces(Fich, Format - i);
  728.         Count := i;
  729.         FileErr := fsWrite(Fich.FileNumber, Count, @Str1[1]);
  730.     end;
  731.  
  732.     procedure WriteReal (var Fich: FileType;
  733.                                     Nb: Extended;
  734.                                     Champ, Fraction: Integer);
  735.  
  736.         var
  737.             s: Str255;
  738.             i: Integer;
  739.  
  740.     begin
  741.         s := ReelToString(Nb, Champ, Fraction);
  742.         i := Length(s);
  743.         WriteSpaces(Fich, Champ - i);
  744.         Count := i;
  745.         FileErr := fsWrite(Fich.FileNumber, Count, @s[1]);
  746.     end;
  747.  
  748.     procedure StringToFile (var f: FileType;
  749.                                     NoStr, Index, NbLn: Integer);
  750.  
  751.         var
  752.             i, crCode: Integer;
  753.             Count: LongInt;
  754.  
  755.     begin
  756.         GetIndString(Str1, NoStr, Index);
  757.         Count := Length(Str1);
  758.         FileErr := fsWrite(f.FileNumber, Count, @Str1[1]);
  759.         CountByte := 1;
  760.         for i := 1 to NbLn do
  761.             WriteLnF(f);
  762.     end;
  763.  
  764.     function SilentDialog (TheDialog: Dialogptr;
  765.                                     var TheEvent: EventRecord;
  766.                                     var ItemHit: Integer): Boolean;
  767.  
  768.         var
  769.             NbTicks: LongInt;
  770.  
  771.     begin
  772.         SystemTask; { Take care of desk accessories }
  773.         DrawDialog(TheDialog);
  774.         NbTicks := TickCount;
  775.         repeat { do this until we selected quit}
  776.         until TickCount - NbTicks > 100; { end of repeat statement }
  777.         SilentDialog := True;
  778.     end;
  779.  
  780.     procedure Erreurs (i, j, k: Integer;
  781.                                     Fatal: Boolean);
  782.  
  783.     begin
  784.         GetIndString(Str1, ErrfatID, i);
  785.         Str3 := '';
  786.         Str4 := '';
  787.         if j > 0 then begin
  788.             NumToString(j, Str3);
  789.             if k > 0 then
  790.                 NumToString(k, Str4);
  791.         end;
  792.         ParamText(Str1, '', Str3, Str4);
  793.         if Fatal then begin
  794.             i := StopAlert(ErrfatID, nil);
  795.             CloseThings;
  796.         end
  797.         else
  798.             i := CautionAlert(ErrfatID, SilentAlert);
  799.         ResetAlertStage;
  800.     end; { fin erreur }
  801.  
  802.     function GetReal (var t: FileType): Extended;
  803.  
  804.         var
  805.             x: Extended;
  806.  
  807.     begin
  808.         Count := ReelBytes;
  809.         FileErr := fsRead(t.FileNumber, Count, @x);
  810.         GetReal := x;
  811.     end;
  812.  
  813.     function GetInteger (var t: FileType): Integer;
  814.  
  815.         var
  816.             i: Integer;
  817.  
  818.     begin
  819.         Count := IntBytes;
  820.         FileErr := fsRead(t.FileNumber, Count, @i);
  821.         GetInteger := i;
  822.     end;
  823.  
  824.     function GetTri (var t: FileType): Trie;
  825.  
  826.         var
  827.             tt: Trie;
  828.  
  829.     begin
  830.         Count := TrieBytes;
  831.         FileErr := fsRead(t.FileNumber, Count, @tt);
  832.         GetTri := tt;
  833.     end;
  834.  
  835.     function NextTri (var t: FileType): Trie;
  836.  
  837.         var
  838.             tt: Trie;
  839.  
  840.     begin
  841.         Count := TrieBytes;
  842.         FileErr := fsRead(t.FileNumber, Count, @tt);
  843.         NextTri := tt;
  844.         FileErr := SetfPos(t.FileNumber, fsFromMark, -Count);
  845.     end;
  846.  
  847.     procedure GetLn (var t: FileType);
  848.  
  849.         var
  850.             i: Integer;
  851.  
  852.     begin
  853.         Count := 1;
  854.         repeat
  855.             FileErr := fsRead(t.FileNumber, Count, @i);
  856.             if FileErr <> 0 then
  857.                 FileErrHandler(t);
  858.         until (i div 256 = 13);
  859.     end;
  860.  
  861.     procedure PutReal (var t: FileType;
  862.                                     x: Extended);
  863.  
  864.     begin
  865.         Count := ReelBytes;
  866.         FileErr := fsWrite(t.FileNumber, Count, @x);
  867.     end;
  868.  
  869.     procedure PutInteger (var t: FileType;
  870.                                     x: Integer);
  871.  
  872.     begin
  873.         Count := IntBytes;
  874.         FileErr := fsWrite(t.FileNumber, Count, @x);
  875.     end;
  876.  
  877.     procedure PutTri (var t: FileType;
  878.                                     x: Trie);
  879.  
  880.     begin
  881.         Count := TrieBytes;
  882.         FileErr := fsWrite(t.FileNumber, Count, @x);
  883.     end;
  884.  
  885.     function TrouveVolume: Integer;
  886.  
  887.         var
  888.             Necessaire, Free: LongInt;
  889.             j, jj: Integer;
  890.             DrivePtr: QHdrPtr;
  891.             ElemPtr: QElemPtr;
  892.  
  893.     begin
  894. { Procédure modifiée 25/05/98 par PhC, rendue inopérante pour CW }
  895.         jj := 0;
  896. {$ifc not undefined THINK_PASCAL}
  897.         DrivePtr := GetDrvqHdr;
  898.         ElemPtr := DrivePtr^.QHead;
  899.         Necessaire := 0;
  900.         repeat
  901.             with ElemPtr^.DrvqElem do begin
  902.                 FileErr := GetVInfo(dqDrive, @Str1, j, Free);
  903.                 if FileErr = 0 then begin
  904.                     if Free > Necessaire then begin
  905.                         Necessaire := Free;
  906.                         jj := j;
  907.                     end;
  908.                 end;
  909.             end;
  910.             ElemPtr := ElemPtr^.DrvqElem.QLink;
  911.         until ElemPtr = nil;
  912. {$endc}
  913.         TrouveVolume := jj;
  914.     end;
  915.  
  916.     procedure TrouveFile (var t: FileType;
  917.                                     Creator, FileType: OSType);
  918.  
  919.         label
  920.             777;
  921.  
  922.         var
  923.             i3, i4, i5: Integer;
  924.  
  925.     begin
  926.         t.Name := 'ZZZZZ';
  927.         for i3 := 26 downto 1 do begin
  928.             t.Name[3] := Chr(64 + i3);
  929.             for i4 := 26 downto 1 do begin
  930.                 t.Name[4] := Chr(64 + i4);
  931.                 for i5 := 26 downto 1 do begin
  932.                     t.Name[5] := Chr(64 + i5);
  933.                     FileErr := Create(t.Name, t.VolNumber, Creator, FileType);
  934.                     if FileErr = 0 then
  935.                         goto 777;
  936.                 end;
  937.             end;
  938.         end;
  939. 777:
  940.         with t do
  941.             FileErr := fsOpen(Name, VolNumber, FileNumber);
  942.         NbFiles := NbFiles + 1;
  943.         with FileArray[NbFiles] do begin
  944.             Delete := True;
  945.             Fichier := @t;
  946.         end;
  947.         FileErrHandler(t);
  948.         t.vName := True;
  949.     end;
  950.  
  951.     procedure InitThings (AttendCRMouse: Boolean);
  952.  
  953.     begin
  954.         MaxApplZone;
  955. {$ifc undefined THINK_PASCAL}
  956.         InitGraf(@qd.ThePort);
  957. {$elsec}
  958.         InitGraf(@ThePort);
  959. {$endc}
  960.         MoreMasters;
  961.         MoreMasters;
  962.         MoreMasters;
  963.         MoreMasters;
  964.         MoreMasters;
  965.         MoreMasters;
  966.         MoreMasters;
  967.         ClockCursor := GetCursor(WatchCursor);
  968.         TextCursor := GetCursor(iBeamCursor);
  969.         hLock(Handle(ClockCursor));
  970.         hLock(Handle(TextCursor));
  971.         SetCursor(ClockCursor^^);
  972.         InitFonts;
  973.         InitWindows;
  974.         InitMenus;
  975.         TEInit;
  976.         InitDialogs(nil);
  977.         FlushEvents(EveryEvent, 0);
  978.         AppleMenu := GetMenu(AppleID);
  979.         TextFont(SystemFont);
  980.         SetMenuItemText(AppleMenu, 0, Chr(20));
  981.         EditMenu := GetMenu(EditID);
  982.         MenuHdl := GetMenu(MenuID);
  983.         AppendResMenu(AppleMenu, 'DRVR'); { Add desk accessories }
  984.         InsertMenu(AppleMenu, 0);
  985.         MenuFile := GetMenu(FileMenuID);
  986.         InsertMenu(MenuFile, 0);
  987.         DisableItem(MenuFile, 2);
  988.         InsertMenu(EditMenu, 0);
  989.         InsertMenu(MenuHdl, 0);
  990.         DisableItem(MenuHdl, 2);
  991.         DrawMenubar;
  992.         InitCursor;
  993.         TheCard := GetNewDialog(CardID, nil, Pointer(-1));
  994.         if AttendCRMouse then
  995.             repeat
  996.                 ModalDialog(nil, ItemHit);
  997.             until ItemHit = ok;
  998. { Mod. PhC 11/02/98: cette instruction crashe le PowerPC... }
  999. {    ClipRect(ScreenBits.Bounds);}
  1000.         Sortie.vName := False;
  1001.         vPrinter := False;
  1002.         DrawMenubar;
  1003.         TitreProg := '';
  1004.         FichierSimil := False;
  1005.         fTitre := '';
  1006.         NObjSimil := 0;
  1007.         NbDescSimil := 0;
  1008.         CountByte := 1;
  1009.         CountInteger := 2;
  1010.         CountLongInt := 4;
  1011.         CountReal := 10;
  1012.         CountSimil := 10;
  1013.         PrInter := False;
  1014.         PgSetup := nil;
  1015.         SilentAlert := nil;
  1016.     end;
  1017.  
  1018.     procedure DeleteFich (var f: FileType);
  1019.  
  1020.         var
  1021.             i: Integer;
  1022.  
  1023.     begin
  1024.         with f do begin
  1025.             FileErr := fsClose(FileNumber);
  1026.             if FileErr = 0 then
  1027.                 FileErr := fsDelete(Name, VolNumber);
  1028.         end;
  1029.     end;
  1030.  
  1031.     function FilterForCursor (TheDialog: Dialogptr;
  1032.                                     var TheEvent: EventRecord;
  1033.                                     var Item: Integer): Boolean;
  1034.  
  1035.         const
  1036.             crCode = 13;
  1037.             Entercode = 3; {ASCII ccode for ENTER}
  1038.             SpaceCode = 32;
  1039.  
  1040.         var
  1041.             MouseLocation: Point;
  1042.             ItemHandle: Handle;
  1043.             Opttype, Car: Integer;
  1044.             TextBox: Rect;
  1045.  
  1046.     begin
  1047.         FilterForCursor := False;
  1048.         Item := 0;
  1049.         GetDialogItem(TheDialog, 3, Opttype, ItemHandle, TextBox);
  1050.         case TheEvent.What of
  1051.             NullEvent:  begin
  1052.                 GetMouse(MouseLocation);
  1053.                 if PtInrect(MouseLocation, TextBox) then
  1054.                     SetCursor(TextCursor^^)
  1055.                 else
  1056. {$ifc undefined THINK_PASCAL}
  1057.                     SetCursor(qd.Arrow);
  1058. {$elsec}
  1059.                 SetCursor(Arrow);
  1060. {$endc}
  1061.             end;
  1062.  
  1063.             KeyDown, AutoKey: {to follow std. PROCEDURE, chk if RETURN or ENTER}
  1064. {                       was pressed}
  1065.                 begin
  1066.                 Car := TheEvent.Message mod 256;
  1067.                 if ((Car = crCode) or (Car = Entercode)) or ((LisNombre) and (Car = SpaceCode)) then begin
  1068.                     FilterForCursor := True;
  1069.                     Item := 1;
  1070.                 end;
  1071.             end;
  1072. { Mod. PhC 11/02/98: case selector out of range }
  1073.             otherwise
  1074.                 ;
  1075.         end; {of the CASE statment}
  1076.     end;
  1077.  
  1078.     procedure Dialoginit (Dialogtype: Integer);
  1079.  
  1080.     begin
  1081.         GetPort(AncienPort);
  1082.         TheDialog := GetNewDialog(Dialogtype, nil, Pointer(-1));
  1083.         SetPort(TheDialog);
  1084.     end;
  1085.  
  1086.     procedure Dialogue;
  1087.  
  1088.         var
  1089.             ItemType: Integer;
  1090.             BoxHandle: Handle;
  1091.             Box: Rect;
  1092.  
  1093.     begin
  1094.         repeat
  1095.             ModalDialog(@FilterForCursor, ItemHit);
  1096.         until ItemHit = ok;
  1097.         GetDialogItem(TheDialog, 3, ItemType, BoxHandle, Box);
  1098.         GetDialogItemText(BoxHandle, Str5);
  1099. {$ifc undefined THINK_PASCAL}
  1100.         SetCursor(qd.Arrow);
  1101. {$elsec}
  1102.         SetCursor(Arrow);
  1103. {$endc}
  1104.     end;
  1105.  
  1106.     procedure RetourneDialogue;
  1107.  
  1108.     begin
  1109.         DisposeDialog(TheDialog);
  1110.         SetPort(AncienPort);
  1111.     end;
  1112.  
  1113.     function QuestionBinaire (i: Integer): Boolean;
  1114.  
  1115.     begin
  1116.         GetIndString(Str1, QbinaireID, i);
  1117.         ParamText(Str1, '', '', '');
  1118.         QuestionBinaire := (Alert(QbinaireID, nil) = 1);
  1119.     end;
  1120.  
  1121.     procedure ErrNombre (i: Integer);
  1122.  
  1123.         var
  1124.             ItemType: Integer;
  1125.             ItemHandle: Handle;
  1126.             DispRect: Rect;
  1127.  
  1128.     begin
  1129.         GetIndString(Str2, ErrNbID, i);
  1130.         ErrNb := True;
  1131.         GetDialogItem(TheDialog, 5, ItemType, ItemHandle, DispRect);
  1132.         SetDialogItemText(ItemHandle, Str2);
  1133.     end;
  1134.  
  1135.     function StringToInteger (var Str: Str255;
  1136.                                     LimInf, LimSup: Integer): Integer;
  1137.  
  1138.         var
  1139.             i, Nb, Longueur, Debut, Facteur, Car: Integer;
  1140.             Negatif: Boolean;
  1141.  
  1142.     begin
  1143.         Nb := 0;
  1144.         Longueur := Length(Str);
  1145.         Facteur := 1;
  1146.         Negatif := False;
  1147.         Debut := 1;
  1148.         if Str[1] = '-' then begin
  1149.             Debut := 2;
  1150.             Negatif := True;
  1151.         end
  1152.         else if Str[1] = '+' then
  1153.             Debut := 2;
  1154.         for i := Longueur downto Debut do begin
  1155.             Car := Ord(Str[i]) - Ord('0');
  1156.             if (Car < 0) or (Car > 9) then
  1157.                 ErrNombre(1)
  1158.             else begin
  1159.                 Nb := Nb + Facteur * Car;
  1160.                 Facteur := Facteur * 10;
  1161.             end;
  1162.         end;
  1163.         if Negatif then
  1164.             Nb := -Nb;
  1165.         if (Nb < LimInf) or (Nb > LimSup) then
  1166.             ErrNombre(2)
  1167.         else
  1168.             StringToInteger := Nb;
  1169.     end;
  1170.  
  1171.     function Entier (i, LimInf, LimSup: Integer;
  1172.                                     St, StrDefault: StringPtr): Integer;
  1173.  
  1174.         var
  1175.             j: LongInt;
  1176.             Debut, Opttype: Integer;
  1177.             ItemHandle: Handle;
  1178.             TextBox: Rect;
  1179.  
  1180.     begin
  1181.         LisNombre := True;
  1182.         GetIndString(Str1, IntID, i);
  1183.         ParamText(Str1, '', St^, '');
  1184.         Dialoginit(ReelID);
  1185.         if StrDefault <> nil then begin
  1186.             GetDialogItem(TheDialog, 3, Opttype, ItemHandle, TextBox);
  1187.             SetDialogItemText(ItemHandle, StrDefault^);
  1188.             SelectDialogItemText(TheDialog, 3, 0, Length(StrDefault^)); { select it }
  1189.         end;
  1190.         repeat
  1191.             ErrNb := False;
  1192.             Dialogue;
  1193.             j := StringToInteger(Str5, LimInf, LimSup);
  1194.         until not (ErrNb);
  1195.         Debut := 1;
  1196.         while Str5[Debut] in [' ', ' '] do
  1197.             Debut := Debut + 1;
  1198.         if Str5[Debut] = '-' then
  1199.             j := -j;
  1200.         RetourneDialogue;
  1201.         Entier := j;
  1202.     end;
  1203.  
  1204.     function StringToReel (var Str: Str255): Extended;
  1205.  
  1206.         var
  1207. {$ifc undefined THINK_PASCAL}
  1208.             ValidPrefix: Integer;
  1209. {$elsec}
  1210.             ValidPrefix: Boolean;
  1211. {$endc}
  1212.             s: DecStr;
  1213.             Index: Integer;
  1214.             d: Decimal;
  1215.             Ff: record
  1216.                     case Boolean of
  1217.                         True: (
  1218.                                 f: Extended
  1219.                         );
  1220.                         False: (
  1221.                                 R: Extended
  1222.                         );
  1223.                 end;
  1224.  
  1225.     begin
  1226.         Index := 1;
  1227.         s := Str;
  1228. {$ifc undefined THINK_PASCAL}
  1229.         Str2Dec(@s, Index, d, ValidPrefix);
  1230. {$elsec}
  1231.         Str2Dec(s, Index, d, ValidPrefix);
  1232. {$endc}
  1233.         if not Boolean(ValidPrefix) then
  1234.             ErrNombre(1);
  1235.         Ff.f := Str2Num(s);
  1236.         StringToReel := Ff.R;
  1237.     end;
  1238.  
  1239.     function Reel (i: Integer;
  1240.                                     Min, Max: Extended;
  1241.                                     StrDefault: StringPtr): Extended;
  1242.  
  1243.         var
  1244.             Val: Extended;
  1245.             ItemHandle: Handle;
  1246.             TextBox: Rect;
  1247.             Opttype: Integer;
  1248.  
  1249.     begin
  1250.         LisNombre := True;
  1251.         GetIndString(Str1, ReelID, i);
  1252.         ParamText(Str1, '', '', '');
  1253.         Dialoginit(ReelID);
  1254.         if StrDefault <> nil then begin
  1255.             GetDialogItem(TheDialog, 3, Opttype, ItemHandle, TextBox);
  1256.             SetDialogItemText(ItemHandle, StrDefault^);
  1257.             SelectDialogItemText(TheDialog, 3, 0, Length(StrDefault^)); { select it }
  1258.         end;
  1259.         repeat
  1260.             ErrNb := False;
  1261.             Dialogue;
  1262.             Val := StringToReel(Str5);
  1263.             if (Val < Min) or (Val > Max) then
  1264.                 ErrNombre(2);
  1265.         until not (ErrNb);
  1266.         Reel := Val;
  1267.         RetourneDialogue;
  1268.     end;
  1269.  
  1270.     procedure PrintSetup;
  1271.  
  1272.         var
  1273.             TrueOrFalse: Boolean;
  1274.             DumpgSetup: TPrint;
  1275.  
  1276.     begin
  1277.         PrOpen;
  1278.         if PgSetup <> nil then begin
  1279.             hUnlock(Handle(PgSetup));
  1280.             DisposeHandle(Handle(PgSetup));
  1281.         end;
  1282.         PgSetup := ThPrint(NewHandle(SizeOf(DumpgSetup))); {make handle}
  1283.         PrIntDefault(PgSetup); {initialize the fields}
  1284.         hLock(Handle(PgSetup));
  1285.         InitCursor;
  1286.         TrueOrFalse := PrValidate(PgSetup); { make sure handle is valid}
  1287.         TrueOrFalse := PrStlDialog(PgSetup); { fill the record with the info}
  1288.         InitCursor;
  1289.         PrClose;
  1290.     end;
  1291.  
  1292.     procedure CreeSortie (var Sortie: FileType;
  1293.                                     Ind1, Ind2: Integer);
  1294.  
  1295.         label
  1296.             777;
  1297.  
  1298.         var
  1299.             j, k: Integer;
  1300.  
  1301.     begin
  1302.         Coord.h := 50;
  1303.         Coord.v := 50;
  1304.         GetIndString(Str2, FichID, Ind1);
  1305.         GetIndString(Str1, FichID, Ind2);
  1306.         sfputfile(Coord, Str2, Str1, nil, Sfr);
  1307.         with Sfr do begin
  1308.             if not (Good) then
  1309.                 CloseThings
  1310.             else begin
  1311. 777:
  1312.                 FileErr := Create(fName, vRefNum, 'R*ch', 'TEXT');
  1313.                 if FileErr = DupfnErr then begin
  1314.                     FileErr := fsDelete(fName, vRefNum);
  1315.                     goto 777;
  1316.                 end;
  1317.                 FileErrHandler(Sortie);
  1318.                 FileErr := fsOpen(fName, vRefNum, Sortie.FileNumber);
  1319.                 FileErrHandler(Sortie);
  1320.                 with Sortie do begin
  1321.                     vName := True;
  1322.                     Name := fName;
  1323.                     VolNumber := vRefNum;
  1324.                     NbFiles := NbFiles + 1;
  1325.                     with FileArray[NbFiles] do begin
  1326.                         Delete := False;
  1327.                         Fichier := @Sortie;
  1328.                     end;
  1329.                 end;
  1330.             end;
  1331.         end;
  1332.     end;
  1333.  
  1334. {--------------------------- set the page setup info ---------------------------}
  1335.  
  1336.     function DoSetup: Boolean;
  1337.  
  1338.         var
  1339.             TrueOrFalse, PrNonValide: Boolean;
  1340.             DumpgSetup: TPrint;
  1341.  
  1342.     begin
  1343.         InitCursor;
  1344.         if PgSetup = nil then begin
  1345.             PgSetup := ThPrint(NewHandle(SizeOf(DumpgSetup))); {make handle}
  1346.             PrIntDefault(PgSetup); {initialize the fields}
  1347.             hLock(Handle(PgSetup));
  1348.         end;
  1349.         PrNonValide := PrValidate(PgSetup); { make sure handle is valid}
  1350.         if PrNonValide then
  1351.             TrueOrFalse := PrStlDialog(PgSetup) { fill the record with the info}
  1352.         else
  1353.             TrueOrFalse := True;
  1354.         InitCursor;
  1355.         DoSetup := (TrueOrFalse);
  1356.     end;
  1357.  
  1358. {-------------------------- get and print the document -------------------------}
  1359.  
  1360.     procedure DoPrint (var f: FileType;
  1361.                                     Dessin: PicHandle;
  1362.                                     DessinRect: Rect;
  1363.                                     Setup: Boolean);
  1364.  
  1365.         var
  1366. {$ifc undefined THINK_PASCAL}
  1367.             MyPrPort: TpprPortRef;
  1368. {$elsec}
  1369.             MyPrPort: TpprPort;
  1370. {$endc}
  1371.             Mystrec: TprStatus;
  1372.             Pg, Largeur: Integer;
  1373.             Done: Boolean;
  1374.             PgWidth, PgHeight, CurrentLine, NumLines, BaseLine, NumSpacesInTab, Index: Integer;
  1375.             Facteur: Extended;
  1376.             GotIt, Toto: Boolean;
  1377.             TabStarts: array[1..30] of Integer;
  1378.             PenPoint: Point;
  1379.             Count: Integer;
  1380.             Secs: LongInt;
  1381.             Date: DateTimeRec;
  1382.  
  1383.     begin { DOPRINT }
  1384.         InitCursor;
  1385.         if Setup then
  1386.             Toto := PrJobDialog(PgSetup)
  1387.         else
  1388.             Toto := True;
  1389.         if Toto then {print the document}
  1390.             begin
  1391.             SetCursor(ClockCursor^^);
  1392.             MyPrPort := PrOpenDoc(PgSetup, nil, nil);
  1393.             Pg := 1;
  1394.             GetDateTime(Secs);
  1395.             SecondsToDate(Secs, Date);
  1396.             NumToString(Date.Month, Str2);
  1397.             Str1 := Concat(TitreProg, '    ', Str2, '/');
  1398.             NumToString(Date.Day, Str2);
  1399.             Str1 := Concat(Str1, Str2, '/');
  1400.             NumToString(Date.Year - 1900, Str2);
  1401.             Str1 := Concat(Str1, Str2, '    ');
  1402.  
  1403.             NumToString(Date.Hour, Str2);
  1404.             Str1 := Concat(Str1, Str2, ':');
  1405.             NumToString(Date.Minute, Str2);
  1406.             Str1 := Concat(Str1, Str2, ':');
  1407.             NumToString(Date.Second, Str2);
  1408.             if Date.Second < 10 then
  1409.                 Str1 := Concat(Str1, '0', Str2)
  1410.             else
  1411.                 Str1 := Concat(Str1, Str2);
  1412.             if Dessin <> nil then
  1413.                 Done := True
  1414.             else begin
  1415.                 Done := False;
  1416.           {width in pixels}
  1417. {$ifc undefined THINK_PASCAL}
  1418.                 PgWidth := system.Round(((PgSetup^^.PrInfo.RPage.Right) / (PgSetup^^.PrInfo.ihRes)) * 72);
  1419. {$elsec}
  1420.                 PgWidth := Round(((PgSetup^^.PrInfo.RPage.Right) / (PgSetup^^.PrInfo.ihRes)) * 72);
  1421. {$endc}
  1422.  
  1423.           {height in pixels}
  1424. {$ifc undefined THINK_PASCAL}
  1425.                 PgHeight := system.Round(((PgSetup^^.PrInfo.RPage.Bottom) / (PgSetup^^.PrInfo.ivres)) * 72);
  1426. {$elsec}
  1427.                 PgHeight := Round(((PgSetup^^.PrInfo.RPage.Bottom) / (PgSetup^^.PrInfo.ivres)) * 72);
  1428. {$endc}
  1429.  
  1430.                 BaseLine := 12;
  1431.  
  1432.                 NumLines := (PgHeight div BaseLine) - 4; { get the number of}
  1433. {                                                    lines}
  1434.  
  1435.                 ResetFile(f);
  1436.             end;
  1437.  
  1438.             repeat
  1439.                 if PrError = NoErr then begin
  1440.                     PrOpenPage(MyPrPort, nil); { start new page}
  1441.                     if PrError = NoErr then begin
  1442.                         if Dessin = nil then begin
  1443.                             CurrentLine := 1;
  1444.  
  1445.                             TextFont(4); { monaco = 4 }
  1446.                             TextSize(9);
  1447.                             NumSpacesInTab := 8;
  1448.  
  1449.                             for Index := 1 to 30 do { initialize tab starts}
  1450. {                                             array}
  1451.                                 TabStarts[Index] := (CharWidth(Chr($20)) * NumSpacesInTab * Index) + 20;
  1452.  
  1453.                     {Draw Header}
  1454.                             TextFace([Bold]);
  1455.                             MoveTo(20, CurrentLine * BaseLine);
  1456.                             NumToString(Pg, Str2);
  1457.                             DrawString(Concat(Str1, '         Page ', Str2));
  1458.                             CurrentLine := CurrentLine + 1;
  1459.                             MoveTo(20, CurrentLine * BaseLine);
  1460.                             DrawString(TitreJob);
  1461.                             TextFace([]);
  1462.  
  1463.                             CurrentLine := CurrentLine + 2;
  1464.  
  1465.                     {Draw lines of page}
  1466.                             for CurrentLine := CurrentLine to NumLines + 2 do
  1467.                                 if not Done then begin
  1468.                                     Str3 := ReadString(f, True);
  1469.                                     MoveTo(20, CurrentLine * BaseLine);
  1470.                                     for Index := 1 to Length(Str3) do begin
  1471.                                         if Str3[Index] = Chr($9) then {tab}
  1472.                                             begin
  1473.                                             GetPen(PenPoint);
  1474.                                             Count := 1;
  1475.                                             GotIt := False;
  1476.                                             repeat
  1477.                                                 if PenPoint.h >= TabStarts[Count] then
  1478.                                                     Count := Count + 1
  1479.                                                 else begin
  1480.                                                     GotIt := True;
  1481.                                                     MoveTo(TabStarts[Count], PenPoint.v);
  1482.                                                 end;
  1483.                                             until GotIt;
  1484.                                         end
  1485.                                         else
  1486.                                             DrawString(Str3[Index]);
  1487.                                     end;
  1488.                                     if EndOfFile(f) then
  1489.                                         Done := True;
  1490.                                 end;
  1491.  
  1492.                     {Draw Footer}
  1493.                             CurrentLine := CurrentLine + 2;
  1494.                             TextFace([]);
  1495.                         end
  1496.                         else begin
  1497.                             TextFace([Bold]);
  1498.                             MoveTo(20, 20);
  1499.                             DrawString(Str1);
  1500.                             MoveTo(20, 40);
  1501.                             DrawString(TitreJob);
  1502.                             TextFace([]);
  1503.                             with DessinRect do begin
  1504.                         {Facteur:=(PgSetUp^^.prInfo.rPage.Right-20)}
  1505. {                            /(ScreenBits.Bounds.Right);}
  1506. {                        Right:=Round(Right*Facteur)+20;}
  1507. {                        Bottom:=Round((Bottom-Top) * Facteur)+41;}
  1508.                                 Largeur := Right - Left;
  1509.                                 if Right > PgSetup^^.PrInfo.RPage.Right - 20 then
  1510.                                     Right := PgSetup^^.PrInfo.RPage.Right - 20;
  1511.                                 Left := 20;
  1512.                                 Facteur := (Right - Left) / Largeur;
  1513.                                 Facteur := (PgSetup^^.PrInfo.ivres) / (PgSetup^^.PrInfo.ihRes) * Facteur;
  1514. {$ifc undefined THINK_PASCAL}
  1515.                                 Bottom := system.Round((Bottom - Top) * Facteur);
  1516. {$elsec}
  1517.                                 Bottom := Round((Bottom - Top) * Facteur);
  1518. {$endc}
  1519.                                 Top := 61;
  1520.                                 Bottom := Bottom + Top;
  1521.                             end;
  1522.                             DrawPicture(Dessin, DessinRect);
  1523.                         end;
  1524.                     end;
  1525.                     PrClosePage(MyPrPort);
  1526.                 end;
  1527.                 Pg := Pg + 1;
  1528.             until ((PrError <> NoErr) or (Done));
  1529.  
  1530.             PrCloseDoc(MyPrPort);
  1531.             if (PgSetup^^.PrJob.Bjdocloop = bSpoolLoop) and (PrError = NoErr) then
  1532. {$ifc undefined THINK_PASCAL}
  1533.                 PrPicFile(PgSetup, nil, nil, nil, @Mystrec);
  1534. {$elsec}
  1535.             PrPicFile(PgSetup, nil, nil, nil, Mystrec);
  1536. {$endc}
  1537.             if PrError <> NoErr then
  1538.                 SysBeep(1);
  1539.         end;
  1540.     end;
  1541.  
  1542. {----------------------- initialize the page setup record ----------------------}
  1543.  
  1544.     procedure InitPage;
  1545.  
  1546.         var
  1547.             DumpgSetup: TPrint;
  1548.  
  1549.     begin
  1550.         PgSetup := ThPrint(NewHandle(SizeOf(DumpgSetup))); {make handle}
  1551.         PrIntDefault(PgSetup); {initialize the fields}
  1552.         hLock(Handle(PgSetup));
  1553.     end;
  1554.  
  1555.     procedure PrIntImage (Dessin: PicHandle;
  1556.                                     PrintRect: Rect;
  1557.                                     Setup: Boolean);
  1558.  
  1559.     begin
  1560.         PrOpen;
  1561.         vPrinter := True;
  1562.         if DoSetup then
  1563.             DoPrint(Sortie, Dessin, PrintRect, Setup);
  1564.         InitCursor;
  1565.         HiliteMenu(0);
  1566.         PrClose;
  1567.     end;
  1568.  
  1569.     procedure PrIntFichier (var Fich: FileType);
  1570.  
  1571.         var
  1572.             R: Rect;
  1573.  
  1574.     begin
  1575.         PrOpen;
  1576.         vPrinter := True;
  1577.         SetCursor(ClockCursor^^);
  1578.   {if not(VPrinter) then PrintInit;}
  1579.         SetRect(R, 0, 0, 0, 0);
  1580.         if DoSetup then
  1581.             DoPrint(Fich, nil, R, True);
  1582.         InitCursor;
  1583.         PrClose;
  1584.     end;
  1585.  
  1586.     procedure LisFich (Ind: Integer;
  1587.                                     var Entree: FileType;
  1588.                                     Stop: Boolean);
  1589.  
  1590.     begin
  1591.         GetIndString(Str1, FichID, Ind);
  1592.         ParamText(Str1, '', '', '');
  1593.         Dialoginit(FichID);
  1594.         DrawDialog(TheDialog);
  1595.         Coord.h := 50;
  1596.         Coord.v := 50;
  1597.         Sft[0] := 'TEXT';
  1598.         sfGetFile(Coord, Str1, @MyFileFilter, 1, @Sft, nil, Sfr);
  1599.         with Sfr do begin
  1600.             if not (Good) then begin
  1601.                 if Stop then
  1602.                     CloseThings;
  1603.             end
  1604.             else begin
  1605.                 fTitre := fName;
  1606.                 FileErr := fsOpen(fName, vRefNum, Entree.FileNumber);
  1607.                 FileErrHandler(Entree);
  1608.                 Entree.VolNumber := vRefNum;
  1609.                 ResetFile(Entree);
  1610.                 Entree.vName := True;
  1611.                 Entree.Name := fName;
  1612.                 NbFiles := NbFiles + 1;
  1613.                 with FileArray[NbFiles] do begin
  1614.                     Delete := False;
  1615.                     Fichier := @Entree;
  1616.                 end;
  1617.             end;
  1618.         end;
  1619.         RetourneDialogue;
  1620.     end;
  1621.  
  1622.     procedure LisFichSimil (Ind: Integer;
  1623.                                     var Entree: FileType;
  1624.                                     Stop: Boolean);
  1625.  
  1626.     begin
  1627.         GetIndString(Str1, FichID, Ind);
  1628.         ParamText(Str1, '', '', '');
  1629.         Dialoginit(FichID);
  1630.         DrawDialog(TheDialog);
  1631.         Coord.h := 50;
  1632.         Coord.v := 50;
  1633.         Sft[0] := 'RSIM';
  1634.         sfGetFile(Coord, Str1, @MyFileFilter, 1, @Sft, nil, Sfr);
  1635.         with Sfr do begin
  1636.             if not (Good) then begin
  1637.                 if Stop then
  1638.                     CloseThings;
  1639.             end
  1640.             else begin
  1641.                 fTitre := fName;
  1642.                 FileErr := fsOpen(fName, vRefNum, Entree.FileNumber);
  1643.                 FileErrHandler(Entree);
  1644.                 Entree.VolNumber := vRefNum;
  1645.                 ResetFile(Entree);
  1646.                 Entree.vName := True;
  1647.                 Entree.Name := fName;
  1648.                 NbFiles := NbFiles + 1;
  1649.                 with FileArray[NbFiles] do begin
  1650.                     Delete := False;
  1651.                     Fichier := @Entree;
  1652.                 end;
  1653.             end;
  1654.         end;
  1655.         RetourneDialogue;
  1656.     end;
  1657.  
  1658.     function LireString (i: Integer): Str255;
  1659.  
  1660.     begin
  1661.         LisNombre := False;
  1662.         GetIndString(Str1, TitreID, i);
  1663.         ParamText(Str1, '', '', '');
  1664.         Dialoginit(TitreID);
  1665.         Dialogue;
  1666.         RetourneDialogue;
  1667.         LireString := Str5;
  1668.     end;
  1669.  
  1670.     procedure InitNelly (Notitle, Max: Integer);
  1671.  
  1672.         var
  1673.             i: Integer;
  1674.  
  1675.     begin
  1676.         Dialoginit(NellyID);
  1677.         if Notitle <> 0 then
  1678.             GetIndString(Str1, NellyID, Notitle);
  1679.         SetwTitle(TheDialog, Str1);
  1680.         GetDialogItem(TheDialog, 1, i, ItemHandle1, Box);
  1681.         GetIndString(Str1, NellyID, 1);
  1682.         SetDialogItemText(ItemHandle1, Str1);
  1683.         GetDialogItem(TheDialog, 2, i, ItemHandle2, Box);
  1684.         GetIndString(Str1, NellyID, 2);
  1685.         SetDialogItemText(ItemHandle2, Str1);
  1686.         GetDialogItem(TheDialog, 3, i, ItemHandle3, Box);
  1687.         GetDialogItem(TheDialog, 4, i, ItemHandle4, Box);
  1688.         NumToString(Max, Str1);
  1689.         SetDialogItemText(ItemHandle3, Str1);
  1690.         DrawDialog(TheDialog);
  1691.     end;
  1692.  
  1693.     procedure NouveauDialogue (ID, j: Integer);
  1694.  
  1695.     begin
  1696.         GetIndString(Str1, ID, j);
  1697.         Dialoginit(ID);
  1698.         GetDialogItem(TheDialog, 1, j, ItemHandle1, Box);
  1699.         SetDialogItemText(ItemHandle1, Str1);
  1700.     end;
  1701.  
  1702.     procedure ProcessMenu (CodeWord: LongInt);
  1703.  
  1704.         var
  1705.             NameHolder: Str255; { the name of the desk acc. }
  1706.             Dummy: Integer; { just a dummy }
  1707.             OldPort: GrafPtr;
  1708.  
  1709.     begin
  1710.         MenuNum := HiWord(CodeWord); { get the menu number }
  1711.         MenuItem := LoWord(CodeWord); { get the item number }
  1712.         if (MenuItem > 0) and (MenuNum < 6000) then { ok to handle the menu? }
  1713.             begin
  1714.             case MenuNum of
  1715.                 AppleID:  begin
  1716.                     GetMenuItemText(AppleMenu, MenuItem, NameHolder);
  1717.                     GetPort(OldPort);
  1718.                     Dummy := Opendeskacc(NameHolder);
  1719.                     SetPort(OldPort);
  1720.                 end;
  1721.                 EditID:  begin
  1722.                     if not SystemEdit(MenuItem - 1) then begin
  1723.                     end;
  1724.                 end;
  1725.                 FileMenuID:  begin
  1726.                     case MenuItem of
  1727.                         0:  begin
  1728.                         end;
  1729.                         1: 
  1730.                             Opennow := True;
  1731.                         2: 
  1732.                             CloseNow := True;
  1733.                         3: 
  1734.                             PrintSetup;
  1735.                     end; {MenuItem}
  1736.                 end;
  1737.  
  1738.                 otherwise begin
  1739.                 end;
  1740.             end; { of case menuNum of }
  1741.             MenuNum := 0;
  1742.             MenuItem := 0;
  1743.         end
  1744.         else if (MenuNum = 6000) and (MenuItem = 1) then
  1745.             CloseThings
  1746.         else if MenuItem = 0 then
  1747.             MenuNum := 0;
  1748.         HiliteMenu(0);
  1749.     end; { of process menu }
  1750.  
  1751.     procedure Interruption;
  1752.  
  1753.     begin
  1754.         repeat
  1755.             NextEvent([InDesk, inMenuBar, Insyswindow, InContent, InDrag, inGrow, inGoAway]);
  1756.         until FrontWindow = TheDialog;
  1757.         DrawDialog(TheDialog);
  1758.     end;
  1759.  
  1760.     procedure NextEvent (Quoi: EventSet);
  1761.  
  1762.         type
  1763.             TrickType = packed record { to get around pascal's typing }
  1764.                     case Boolean of
  1765.                         True: (
  1766.                                 i: LongInt
  1767.                         );
  1768.                         False: (
  1769.                                 Chr3, Chr2, Chr1, Chr0: Char
  1770.                         );
  1771.                 end;
  1772.  
  1773.         var
  1774.             WindowLoc: Integer; { the mouse location }
  1775.             MouseLoc: Point; { the area it was in }
  1776.             TheWindow: WindowPtr; { Dummy,cause we have no windows}
  1777.             TrickVar: TrickType; { because of pascal's typing }
  1778.             CharCode: Char; { for command keys }
  1779.  
  1780.     begin
  1781.         Opennow := False;
  1782.         CloseNow := False;
  1783.         WindowLoc := -1;
  1784.         repeat { do this until we selected quit}
  1785.             SystemTask; { Take care of desk accessories }
  1786.             if GetNextEvent(EveryEvent, TheEvent) then { if there was an}
  1787. {                                                event... then }
  1788.                 begin
  1789.                 case TheEvent.What of { case out on the event type }
  1790.                     MouseDown: { we had a mouse-down event }
  1791.                         begin
  1792.                         MouseLoc := TheEvent.Where; { wheres the pesky mouse }
  1793.                         WindowLoc := FindWindow(MouseLoc, TheWindow); { find out}
  1794. {                where }
  1795.                         case WindowLoc of { now case on the location }
  1796.                             inMenuBar: 
  1797.                                 ProcessMenu(MenuSelect(MouseLoc)); { Handle}
  1798. {                  the selection }
  1799.                             Insyswindow: 
  1800.                                 SystemClick(TheEvent, TheWindow); {It was}
  1801. {                  in a desk acc }
  1802.                         end;
  1803.                     end;
  1804.                     KeyDown, AutoKey: { we had the user hit a key }
  1805.                         begin
  1806.                         TrickVar.i := TheEvent.Message; { fill the longWord }
  1807.                         CharCode := TrickVar.Chr0; { and pull off the low-byte }
  1808.                         if BitAnd(TheEvent.Modifiers, cmdKey) = cmdKey then { if}
  1809. {                   cmd down }
  1810.               { then go handle the menu }
  1811.                             ProcessMenu(MenuKey(CharCode));
  1812.                     end;
  1813. { Modification PhC 11/02/98: case selector out of range }
  1814.                     otherwise
  1815.                         ;
  1816.                 end; { of case event.what... }
  1817.             end;
  1818.         until (WindowLoc in Quoi); { end of repeat statement }
  1819.     end;
  1820.  
  1821.     procedure MiseaJourd (l: Integer);
  1822.  
  1823.     begin
  1824.         if EventAvail(Mdownmask, TheEvent) then
  1825.             Interruption;
  1826.         NumToString(l, Str2);
  1827.         SetDialogItemText(ItemHandle4, Str2);
  1828.     end;
  1829.  
  1830.     procedure MiseaJourg (l: Integer);
  1831.  
  1832.     begin
  1833.         if EventAvail(Mdownmask, TheEvent) then
  1834.             Interruption;
  1835.         NumToString(l, Str2);
  1836.         SetDialogItemText(ItemHandle3, Str2);
  1837.     end;
  1838.  
  1839.     procedure ShowFichier (var Fich: FileType;
  1840.                                     Index: Integer;
  1841.                                     DessinCourant: PicHandle;
  1842.                                     R: Rect;
  1843.                                     ThereWasAWindow: Boolean);
  1844.  
  1845.         var
  1846.             NbLignes, AncienMenuItem, LignesParEcran, PtrLignesSup, PtrLignesInf, i: Integer;
  1847.             RectUp, RectDown, ScrollRegion, ShowRect: Rect;
  1848.             Fini: Boolean;
  1849.             Espace: LongInt;
  1850.             OldPort: GrafPtr;
  1851.             Showwnd: Dialogptr;
  1852.             WindowPtr2: WindowPtr;
  1853.             Upd: RgnHandle;
  1854.             AncienMenu: Handle;
  1855.             NouveauMenu: MenuHandle;
  1856.             Space: PtrType;
  1857.  
  1858.         procedure ScrollInit (var Fich: FileType);
  1859.  
  1860.             var
  1861.                 i, j, k: Integer;
  1862.                 Car: Char;
  1863.  
  1864.             procedure InitScroll;
  1865.  
  1866.             begin
  1867.                 SetCursor(ClockCursor^^);
  1868.                 AncienMenuItem := MenuItem;
  1869.                 AncienMenu := GetMenuBar;
  1870.                 ClearMenuBar;
  1871.                 InsertMenu(GetMenu(AppleID), 0);
  1872.                 MenuFile := GetMenu(FileMenuID);
  1873.                 InsertMenu(MenuFile, 0);
  1874.                 InsertMenu(GetMenu(EditID), 0);
  1875.                 InsertMenu(GetMenu(MenuID), 0);
  1876.                 InsertMenu(GetMenu(MenuPr), 0);
  1877.                 DisableItem(MenuFile, 2);
  1878.                 DrawMenubar;
  1879. {$ifc undefined THINK_PASCAL}
  1880.                 ShowRect := qd.ScreenBits.Bounds;
  1881. {$elsec}
  1882.                 ShowRect := ScreenBits.Bounds;
  1883. {$endc}
  1884.                 Showwnd := NewWindow(nil, ShowRect, 'Triangle', True, 3, WindowPtr(-1), False, Ref);
  1885.                 GetPort(OldPort);
  1886.                 SetPort(Showwnd);
  1887.                 TextFont(4); { 4 = monaco }
  1888.                 SetfScaleDisable(True);
  1889.                 Upd := NewRgn;
  1890.                 Upd^^.RgnSize := 10;
  1891.                 SetRect(Upd^^.RgnbBox, 0, 0, 0, 0);
  1892.                 SetRect(RectDown, 0, ShowRect.Bottom - 20, ShowRect.Right, ShowRect.Bottom - 10);
  1893.                 SetRect(ScrollRegion, 0, MenuHeight, ShowRect.Right, ShowRect.Bottom);
  1894.                 LignesParEcran := (RectDown.Bottom - MenuHeight) div 15 - 1;
  1895.                 RectUp := RectDown;
  1896.                 RectUp.Top := RectDown.Top - (LignesParEcran) * 15;
  1897.                 RectUp.Bottom := RectDown.Bottom - (LignesParEcran) * 15;
  1898.             end;
  1899.  
  1900.         begin
  1901.             InitScroll;
  1902.             ResetFile(Fich);
  1903.             NbLignes := 0;
  1904.             Espace := 0;
  1905.             if not (EndOfFile(Fich)) then
  1906.                 repeat
  1907.                     Str1 := ReadString(Fich, False);
  1908.                     ScrollRect(ScrollRegion, 0, -15, Upd);
  1909. { Mod. 06/03/1998 PhC Cette ligne efface ce qu'on vient d'écrire! }
  1910. { Je la mets donc entre commentaires }
  1911. {EraseRect(RectDown);}
  1912.                     MoveTo(RectDown.Left, RectDown.Bottom);
  1913.                     NbLignes := NbLignes + 1;
  1914.                     DrawString(Str1);
  1915.                 until EndOfFile(Fich);
  1916.             ResetFile(Fich);
  1917.             Space.PtrGen := Memoire(0, NbLignes, 1, 1, LongBytes, True);
  1918.             with AdVec(Space.PtrGen, 0).PtrLong^ do
  1919.                 Long := 0;
  1920.             for i := 1 to NbLignes do begin
  1921.                 Str1 := ReadString(Fich, True);
  1922.                 with AdVec(Space.PtrGen, i).PtrLong^ do
  1923.                     FileErr := GetfPos(Fich.FileNumber, Long);
  1924.             end;
  1925.             InitCursor;
  1926.             PtrLignesSup := NbLignes;
  1927.             PtrLignesInf := PtrLignesSup - LignesParEcran;
  1928.         end;
  1929.  
  1930.         procedure ScrollUpDown;
  1931.  
  1932.             var
  1933.                 OuEstLaSouris: Point;
  1934.                 Sens: Integer;
  1935.  
  1936.         begin
  1937.             while not (GetNextEvent(mUpMask, TheEvent)) do begin
  1938.                 GetMouse(OuEstLaSouris);
  1939.                 GlobalToLocal(OuEstLaSouris);
  1940.                 with OuEstLaSouris do
  1941.                     if (v - ScrollRegion.Top < ScrollRegion.Bottom - v) then
  1942.                         Sens := -1
  1943.                     else
  1944.                         Sens := 1;
  1945.                 if ((Sens = 1) and (PtrLignesSup < NbLignes)) or ((Sens = -1) and (PtrLignesInf > 0)) then begin
  1946.                     PtrLignesSup := PtrLignesSup + Sens;
  1947.                     PtrLignesInf := PtrLignesInf + Sens;
  1948.                     ScrollRect(ScrollRegion, 0, -15 * Sens, Upd);
  1949.                     if Sens = 1 then begin
  1950.                         MoveTo(RectDown.Left, RectDown.Bottom);
  1951.                         EraseRect(RectDown);
  1952.                         with AdVec(Space.PtrGen, PtrLignesSup - 1).PtrLong^ do
  1953.                             FileErr := SetfPos(Fich.FileNumber, fsFromStart, Long);
  1954.                     end
  1955.                     else begin
  1956.                         MoveTo(RectUp.Left, RectUp.Bottom);
  1957.                         EraseRect(RectUp);
  1958.                         with AdVec(Space.PtrGen, PtrLignesInf - 1).PtrLong^ do
  1959.                             FileErr := SetfPos(Fich.FileNumber, fsFromStart, Long);
  1960.                     end;
  1961.                     DrawString(ReadString(Fich, False));
  1962.                 end;
  1963.             end;
  1964.         end;
  1965.  
  1966.     begin
  1967.         ScrollInit(Fich);
  1968.         repeat
  1969.             Fini := False;
  1970.             NextEvent([inMenuBar, InContent]);
  1971.             if FindWindow(TheEvent.Where, WindowPtr2) = InContent then
  1972.                 ScrollUpDown
  1973.             else if MenuNum = MenuPr then begin
  1974.                 Fini := True;
  1975.                 if MenuItem = 1 then begin
  1976.                     if not (Sortie.vName) then
  1977.                         CreeSortie(Sortie, 2, 3);
  1978.                     ResetFile(Fich);
  1979.                     if not (EndOfFile(Fich)) then
  1980.                         repeat
  1981.                             Str1 := ReadString(Fich, False);
  1982.                             WriteString(Sortie, Str1);
  1983.                             WriteLnF(Sortie);
  1984.                         until EndOfFile(Fich);
  1985.                 end
  1986.                 else if MenuItem = 2 then
  1987.                     PrIntFichier(Fich);
  1988.                 HiliteMenu(0);
  1989.             end;
  1990.         until (Fini) and (MenuItem = 3);
  1991. { Mod. 06/03/1998 PhC Ce code cause une erreur -113 Zone Check }
  1992. { Je préfère laisser une petite fuite de mémoire qu'un bug qui plante }
  1993. {    for i := 1 to NbLignes do}
  1994. {    Dispose(AdVec(Space.PtrGen, i).PtrStr);}
  1995.         DisposeMemoire(Space.PtrGen);
  1996.         DisposeWindow(Showwnd);
  1997.         SetPort(OldPort);
  1998.         if ThereWasAWindow then
  1999.             SelectWindow(OldPort); {!!! Modification 12}
  2000. {                                                  juin 1991}
  2001.         MenuItem := AncienMenuItem;
  2002.         ClearMenuBar;
  2003.         SetMenuBar(AncienMenu);
  2004.         DrawMenubar;
  2005.         DrawPicture(DessinCourant, R);
  2006.         EnableItem(MenuFile, 2);
  2007.     end; { ShowFichier }
  2008.  
  2009.     function LisReelorInt (var t: FileType;
  2010.                                     Abort: Boolean): DecStr;
  2011.  
  2012.         var
  2013.             Fait: Boolean;
  2014.             s: DecStr;
  2015.             i, CarInt: Integer;
  2016.             Car: Char;
  2017.             DebutPos, FinPos: LongInt;
  2018.  
  2019.     begin
  2020.         Fait := False;
  2021.         s := '';
  2022.         i := 0;
  2023.         CountByte := 1;
  2024.         if EndOfFile(t) then
  2025.             if Abort then
  2026.                 ErrFile(1, t);
  2027.         while NextCar(t, False) in [Chr(9), Chr(13), ' '] do
  2028.             FileErr := fsRead(t.FileNumber, CountByte, @CarInt);
  2029.         if EndOfFile(t) then
  2030.             if Abort then
  2031.                 ErrFile(1, t);
  2032.         FileErr := GetfPos(t.FileNumber, DebutPos);
  2033.         repeat
  2034.             FileErr := fsRead(t.FileNumber, CountByte, @CarInt);
  2035.         until (NextCar(t, False) in [' ', Chr(9), Chr(13)]) or (EndOfFile(t));
  2036.         FileErr := GetfPos(t.FileNumber, FinPos);
  2037.         FileErr := SetfPos(t.FileNumber, 1, DebutPos);
  2038.         FinPos := FinPos - DebutPos;
  2039.         i := FinPos;
  2040.         FileErr := fsRead(t.FileNumber, FinPos, @s[1]);
  2041.         FileErrHandler(t);
  2042.         s[0] := Chr(i);
  2043.         LisReelorInt := s;
  2044.     end;
  2045.  
  2046.     procedure Erreur2 (var t: FileType);
  2047.  
  2048.         var
  2049.             i, Position, LastCR: LongInt;
  2050.             CarInt, Ligne, Item: Integer;
  2051.  
  2052.     begin
  2053.         Ligne := 1;
  2054.         FileErr := GetfPos(t.FileNumber, Position);
  2055.         ResetFile(t);
  2056.         for i := 1 to Position do begin
  2057.             FileErr := fsRead(t.FileNumber, CountByte, @CarInt);
  2058.             if CarInt div 256 = 13 then begin
  2059.                 Ligne := Ligne + 1;
  2060.                 LastCR := i;
  2061.             end;
  2062.         end;
  2063.         Position := Position - LastCR - 1;
  2064.         FileErr := SetfPos(t.FileNumber, 1, LastCR);
  2065.         Str2 := ReadString(t, False);
  2066.         GetIndString(Str3, ErrFileID, 29);
  2067.         NumToString(Ligne, Str4);
  2068.         GetIndString(Str5, ErrFileID, 30);
  2069.         Str3 := Concat(Str3, Str4, Str5);
  2070.         NumToString(Position, Str4);
  2071.         Str3 := Concat(Str3, Str4);
  2072.         GetIndString(Str4, ErrFileID, 2);
  2073.         ParamText(Str2, Str3, Concat(Str4, t.Name), '');
  2074.         i := StopAlert(ErrFileID, nil);
  2075.         CloseThings;
  2076.     end;
  2077.  
  2078.     function LisReel (var t: FileType;
  2079.                                     Abort: Boolean): Extended;
  2080.  
  2081.         var
  2082. {$ifc undefined THINK_PASCAL}
  2083.             ValidPrefix: Integer;
  2084. {$elsec}
  2085.             ValidPrefix: Boolean;
  2086. {$endc}
  2087.             s: DecStr;
  2088.             Index: Integer;
  2089.             d: Decimal;
  2090.             Ff: record
  2091.                     case Boolean of
  2092.                         True: (
  2093.                                 f: Extended
  2094.                         );
  2095.                         False: (
  2096.                                 R: Extended
  2097.                         );
  2098.                 end;
  2099.  
  2100.     begin
  2101.         Index := 1;
  2102.         s := LisReelorInt(t, Abort);
  2103. {$ifc undefined THINK_PASCAL}
  2104.         Str2Dec(@s, Index, d, ValidPrefix);
  2105. {$elsec}
  2106.         Str2Dec(s, Index, d, ValidPrefix);
  2107. {$endc}
  2108.         if not Boolean(ValidPrefix) then
  2109.             Erreur2(t);
  2110.         Ff.f := Str2Num(s);
  2111.         LisReel := Ff.R;
  2112.     end;
  2113.  
  2114.     function LisEntier (var t: FileType;
  2115.                                     Abort: Boolean): LongInt;
  2116.  
  2117.         var
  2118.             i, Debut: Integer;
  2119.             l: LongInt;
  2120.             s: DecStr;
  2121.  
  2122.     begin
  2123.         s := LisReelorInt(t, Abort);
  2124.         Debut := 1;
  2125.         if s[1] in ['-', '+'] then
  2126.             Debut := 2;
  2127.         for i := Debut to Length(s) do
  2128.             if not (s[i] in ['0'..'9']) then
  2129.                 Erreur2(t);
  2130.         StringToNum(s, l);
  2131.         LisEntier := l;
  2132.     end;
  2133.  
  2134.     function LisID (var t: FileType;
  2135.                                     Abort: Boolean): Alpha;
  2136.  
  2137.         var
  2138.             i: Integer;
  2139.             Beta: Alpha;
  2140.  
  2141.     begin
  2142.         if EndOfFile(t) then
  2143.             if Abort then
  2144.                 ErrFile(1, t);
  2145.         for i := 1 to 10 do begin
  2146.             if EndOfFile(t) then
  2147.                 if Abort then
  2148.                     ErrFile(1, t);
  2149.             FileErr := fsRead(t.FileNumber, CountByte, @Beta[i]);
  2150.         end;
  2151.         LisID := Beta;
  2152.     end;
  2153.  
  2154.     function Memoire (Min1, Max1, Min2, Max2, lgBytes: LongInt;
  2155.                                     Piege: Boolean): Ptr;
  2156.  
  2157.         var
  2158.             Space: Size;
  2159.             ThePtr: PtrType;
  2160.  
  2161.     begin
  2162.         with ThePtr do begin
  2163.             NumToString(lgBytes, Str1);
  2164.             NumToString(Max1, Str3);
  2165.             Space := Max1 - Min1 + 1;
  2166.             Space := Space * (Max2 - Min2 + 1);
  2167.             Space := Space * lgBytes + 8;
  2168.             NumToString(Space, Str2);
  2169.             PtrGen := NewPtr(Space);
  2170.             with PtrInfo^ do begin
  2171.                 OffSet1 := Min1;
  2172.                 OffSet2 := Min2;
  2173.                 Rang := Max2 - Min2 + 1;
  2174.                 NbBytes := lgBytes;
  2175.             end;
  2176.             PtrEnt := PtrEnt + 8;
  2177.         end;
  2178.         if (MemError <> 0) and (Piege) then
  2179.             Erreurs(1, 0, 0, True)
  2180.         else
  2181.             Memoire := ThePtr.PtrGen;
  2182.     end;
  2183.  
  2184.     procedure DisposeMemoire (var ThePtr: Ptr);
  2185.  
  2186.         var
  2187.             a: PtrType;
  2188.  
  2189.     begin
  2190.         a.PtrGen := ThePtr;
  2191.         with a do begin
  2192.             PtrEnt := PtrEnt - 8;
  2193.             DisposePtr(PtrGen);
  2194.         end;
  2195.         ThePtr := nil;
  2196.     end;
  2197.  
  2198.     function AdMat (p: Ptr;
  2199.                                     v1, v2: LongInt): PtrType;
  2200.  
  2201.         var
  2202.             a, b: PtrType;
  2203.  
  2204.     begin
  2205.         a.PtrGen := p;
  2206.         b.PtrEnt := a.PtrEnt - 8;
  2207.         with b.PtrInfo^ do
  2208.             a.PtrEnt := a.PtrEnt + ((v1 - OffSet1) * Rang + (v2 - OffSet2)) * NbBytes;
  2209.         AdMat := a;
  2210.     end;
  2211.  
  2212.     {Function AdVec(P:Ptr;V:LongInt):PtrType;}
  2213. {    var a,b:PtrType;}
  2214. {        Mn,Mx:LongInt;}
  2215. {        By:Byte;}
  2216. {    begin}
  2217. {    a.PtrGen:=P;}
  2218. {    b.PtrEnt:=a.PtrEnt-14;}
  2219. {    By:=b.PtrInt^.Int;}
  2220. {    Mx:=By+a.PtrEnt;}
  2221. {    Mn:=a.PtrEnt;}
  2222. {    b.PtrEnt:=a.PtrEnt-8;}
  2223. {    with b.PtrInfo^ do}
  2224. {      a.PtrEnt:=a.PtrEnt+(V-Offset1)*NbBytes;}
  2225. {    if  (Numeros)then}
  2226. {      if (a.PtrEnt > Mx)Or(a.PtrEnt < Mn) then}
  2227. {        begin}
  2228. {        NumToString(Mn,Str1);}
  2229. {        NumToString(a.PtrEnt,Str2);}
  2230. {        NumToString(Mx,Str3);}
  2231. {        NumToString(v,Str4);}
  2232. {        DebugStr(Concat('AdVec ',Str4,' ',Str1,' ',Str2,' ',Str3));}
  2233. {        end;}
  2234. {    AdVec:=A;}
  2235. {    end;}
  2236.  
  2237.     function AdVec (p: Ptr;
  2238.                                     v: LongInt): PtrType;
  2239.  
  2240.         var
  2241.             a, b: PtrType;
  2242.  
  2243.     begin
  2244.         a.PtrGen := p;
  2245.         b.PtrEnt := a.PtrEnt - 8;
  2246.         with b.PtrInfo^ do
  2247.             a.PtrEnt := a.PtrEnt + (v - OffSet1) * NbBytes;
  2248.         AdVec := a;
  2249.     end;
  2250.  
  2251.     function AdLin (p: Ptr;
  2252.                                     v1, v2: Integer): PtrType;
  2253.  
  2254.         var
  2255.             a, b: PtrType;
  2256.             Ad: LongInt;
  2257.  
  2258.     begin
  2259.         Ad := v1;
  2260.         Ad := Ad * (Ad - 1) div 2 + v2 - 1;
  2261.         a.PtrGen := p;
  2262.         b.PtrEnt := a.PtrEnt - 8;
  2263.         with b.PtrInfo^ do
  2264.             a.PtrEnt := a.PtrEnt + Ad * NbBytes;
  2265.         AdLin := a;
  2266.     end;
  2267.  
  2268.     function AdBits (mm: Ptr;
  2269.                                     i: Integer): PtrType;
  2270.  
  2271.     begin
  2272.         AdBits.PtrEnt := Ord(mm) + i * BitsBytes;
  2273.     end;
  2274.  
  2275.     function Membre (Ind: Integer;
  2276.                                     mm: Ptr): Boolean;
  2277.  
  2278.         var
  2279.             i, j: Integer;
  2280.  
  2281.     begin
  2282.         i := Ind div NbBits;
  2283.         j := Ind mod NbBits;
  2284.         with AdBits(mm, i).PtrBits^ do
  2285.             Membre := j in Bits;
  2286.     end;
  2287.  
  2288.     procedure Ajoute (Ind: Integer;
  2289.                                     mm: Ptr);
  2290.  
  2291.         var
  2292.             i: Integer;
  2293.  
  2294.     begin
  2295.         i := Ind div NbBits;
  2296.         with AdBits(mm, i).PtrBits^ do
  2297.             Bits := Bits + [Ind mod NbBits];
  2298.     end;
  2299.  
  2300.     procedure Enleve (Ind: Integer;
  2301.                                     mm: Ptr);
  2302.  
  2303.         var
  2304.             i: Integer;
  2305.  
  2306.     begin
  2307.         i := Ind div NbBits;
  2308.         with AdBits(mm, i).PtrBits^ do
  2309.             Bits := Bits - [Ind mod NbBits];
  2310.     end;
  2311.  
  2312.     function Card (x: Ens): Integer;
  2313.  
  2314.         var
  2315.             c, i: Integer;
  2316.  
  2317.     begin
  2318.         c := 0;
  2319.         if x <> [] then
  2320.             for i := 0 to NbBitsl1 do
  2321.                 if i in x then
  2322.                     c := c + 1;
  2323.         Card := c;
  2324.     end; { card }
  2325.  
  2326.     procedure Copy (m1, m2: Ptr);
  2327.  
  2328.         var
  2329.             i: Integer;
  2330.  
  2331.     begin
  2332.         for i := 0 to NbMots do begin
  2333.             with AdBits(m1, i).PtrBits^ do
  2334.                 Bits := AdBits(m2, i).PtrBits^.Bits;
  2335.         end;
  2336.     end;
  2337.  
  2338.     function Vide (m: Ptr): Boolean;
  2339.  
  2340.         var
  2341.             i: Integer;
  2342.             b: Boolean;
  2343.  
  2344.     begin
  2345.         b := True;
  2346.         for i := 0 to NbMots do begin
  2347.             with AdBits(m, i).PtrBits^ do
  2348.                 if Bits <> [] then
  2349.                     b := False;
  2350.         end;
  2351.         Vide := b;
  2352.     end;
  2353.  
  2354.     procedure NullVec (m: Ptr);
  2355.  
  2356.         var
  2357.             i: Integer;
  2358.  
  2359.     begin
  2360.         for i := 0 to NbMots do begin
  2361.             with AdBits(m, i).PtrBits^ do
  2362.                 Bits := [];
  2363.         end;
  2364.     end;
  2365.  
  2366.     procedure Union (m1, m2: Ptr);
  2367.  
  2368.         var
  2369.             i: Integer;
  2370.  
  2371.     begin
  2372.         for i := 0 to NbMots do begin
  2373.             with AdBits(m1, i).PtrBits^ do
  2374.                 Bits := Bits + AdBits(m2, i).PtrBits^.Bits;
  2375.         end;
  2376.     end;
  2377.  
  2378.     procedure Intersection (m0, m1, m2: Ptr);
  2379.  
  2380.         var
  2381.             i: Integer;
  2382.  
  2383.     begin
  2384.         for i := 0 to NbMots do begin
  2385.             with AdBits(m0, i).PtrBits^ do
  2386.                 Bits := AdBits(m1, i).PtrBits^.Bits * AdBits(m2, i).PtrBits^.Bits;
  2387.         end;
  2388.     end;
  2389.  
  2390.     function InclusEgal (m1, m2: Ptr): Boolean;
  2391.  
  2392.         var
  2393.             i: Integer;
  2394.             bb: Boolean;
  2395.  
  2396.     begin
  2397.         bb := True;
  2398.         for i := 0 to NbMots do begin
  2399.             with AdBits(m1, i).PtrBits^ do
  2400.                 if not (Bits <= AdBits(m2, i).PtrBits^.Bits) then
  2401.                     bb := False;
  2402.         end;
  2403.         InclusEgal := bb;
  2404.     end;
  2405.  
  2406.     function Egal (m1, m2: Ptr): Boolean;
  2407.  
  2408.         var
  2409.             i: Integer;
  2410.             bb: Boolean;
  2411.  
  2412.     begin
  2413.         bb := True;
  2414.         for i := 0 to NbMots do begin
  2415.             with AdBits(m1, i).PtrBits^ do
  2416.                 if Bits <> AdBits(m2, i).PtrBits^.Bits then
  2417.                     bb := False;
  2418.         end;
  2419.         Egal := bb;
  2420.     end;
  2421.  
  2422.     procedure Difference (m1, m2: Ptr);
  2423.  
  2424.         var
  2425.             i: Integer;
  2426.  
  2427.     begin
  2428.         for i := 0 to NbMots do begin
  2429.             with AdBits(m1, i).PtrBits^ do
  2430.                 Bits := Bits - AdBits(m2, i).PtrBits^.Bits;
  2431.         end;
  2432.     end;
  2433.  
  2434.     function CardVect (m: Ptr): Integer;
  2435.  
  2436.         var
  2437.             i, Compte: Integer;
  2438.  
  2439.     begin
  2440.         Compte := 0;
  2441.         for i := 0 to NbMots do begin
  2442.             with AdBits(m, i).PtrBits^ do
  2443.                 Compte := Compte + Card(Bits);
  2444.         end;
  2445.         CardVect := Compte;
  2446.     end;
  2447.  
  2448.     procedure Premier (var i: Integer;
  2449.                                     t: Ptr);
  2450.  
  2451.     begin
  2452.         i := 0;
  2453.         repeat
  2454.             i := i + 1;
  2455.         until Membre(i, t);
  2456.     end;
  2457. end.